#ifndef _LIB_SIDECAR_HPP_
#define _LIB_SIDECAR_HPP_

#include <iostream>

#include "hiredis.h"

using namespace std;

class Sidecar {
    public:
        Sidecar(redisContext* redis_ctx);
        ~Sidecar();

        static Sidecar* init(const char* ip_addr="127.0.0.1", int port=6379);
        static Sidecar* reconnect(Sidecar* sidecar, const char* ip_addr="127.0.0.1", int port=6379);
        static void destroy(Sidecar* sidecar);

        long long get_int_value(const char* url, const char* metrics);
        double get_float_value(const char* url, const char* metrics);
        int get_str_value(const char* url, const char* metrics, char* str, size_t* str_len);
        int get_struct_value(const char* url, const char* metrics, char* value, size_t* value_len);

        int set_int_value(const char* url, const char* metrics, long long value);
        int incr_int_value(const char* url, const char* metrics);
        int decr_int_value(const char* url, const char* metrics);
        int add_int_value(const char* url, const char* metrics, long long value);

        int set_float_value(const char* url, const char* metrics, double value);
        int set_str_value(const char* url, const char* metrics, const char* value, size_t value_len);
        int set_struct_value(const char* url, const char* metrics, const char* data, size_t value_len);

    private:
        Sidecar();

        redisContext* _redis_ctx;
};

#endif
